package com.example.mapp.buildSql;

import com.example.entity.authority.PartyContractProject;
import org.apache.commons.lang3.StringUtils;

public class PartyContractProjectMappSql {

    /**
     * @param partyContract
     * @return
     */
    public String updateContractProject(PartyContractProject partyContract){
        StringBuilder builder = new StringBuilder("update party_contract_project set elevator_ids=#{elevatorIds}, ");
        StringBuilder setValue = new StringBuilder();
        if(partyContract.getElevatorCount() != null){
            setValue.append(" elevator_count=#{elevatorCount},");
        }
        /*if(StringUtils.isNotEmpty(partyContract.getElevatorIds())){
            setValue.append(" elevator_ids=#{elevatorIds},");
        }*/
        if(StringUtils.isNotEmpty(partyContract.getOnePrice())){
            setValue.append(" one_price=#{onePrice},");
        }
        if(StringUtils.isNotEmpty(partyContract.getProjectAddress())){
            setValue.append(" project_address=#{projectAddress},");
        }
        if(StringUtils.isNotEmpty(partyContract.getProjectName())){
            setValue.append(" project_name=#{projectName},");
        }
        if(StringUtils.isNotEmpty(partyContract.getStarTime())){
            builder.append(" star_time=#{starTime},");
        }
        if(StringUtils.isNotEmpty(partyContract.getEndTime())){
            builder.append(" end_time=#{endTime},");
        }
        if(StringUtils.isNotEmpty(partyContract.getProjectArea())){
            builder.append(" project_area=#{projectArea} ,");
        }
        if(StringUtils.isNotEmpty(partyContract.getProjectCity())){
            builder.append("project_city=#{projectCity},");
        }
        if(StringUtils.isNotEmpty(partyContract.getProjectProvince())){
            builder.append(" project_province=#{projectProvince},");
        }

        builder.append(setValue.substring(0,setValue.lastIndexOf(","))).append(" where 1=1 ");
        if(partyContract.getId() != null){
            builder.append(" and id = #{id}");
        }
        return builder.toString();
    }
}
